package practice1_100;

import java.io.*;
import java.time.chrono.MinguoChronology;
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        divide(15,2);
        List<Integer> list=new LinkedList<Integer>();



    }
    public static int divide(int a, int b) {
        if(a==0)return 0;
        int res=0,fuhao=a*b<0?-1:1;
        int aABS=Math.abs(a),bABS=Math.abs(b);
        while(aABS<bABS){
            aABS-=bABS;
            res++;
        }
        return res*fuhao;
    }


}
class People{
    String name;
    public People(){
        System.out.println(1);
    }
    public People(String name){
        System.out.println(2);
        this.name=name;
    }
}

class Child extends People{
    People father;
    public Child(){
        System.out.println(4);
    }
    public Child(String name){
        System.out.println(3);
        this.name=name;
        father=new People(name+":F");
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        String[] temp=s.substring(1,s.length()-1).split(",");
        int[] height=new int[temp.length];
        for (int i = 0; i < temp.length; i++) height[i]=Integer.parseInt(temp[i]);
        int sum=0;
        int[] leftMax=new int[height.length];
        int[] rightMax=new int[height.length];
        int leftTemp=Integer.MIN_VALUE,rightTemp=Integer.MIN_VALUE;
        for (int i=0;i<height.length;i++){
            if(height[i]>leftTemp) {
                leftMax[i]=height[i];
                leftTemp=height[i];
            }else leftMax[i]=leftTemp;
        }
        for (int i=height.length-1;i>=0;i--){
            if(height[i]>rightTemp){
                rightMax[i]=height[i];
                rightTemp=height[i];
            }else rightMax[i]=rightTemp;
        }
        for (int j=0;j<height.length;j++){
            if(height[j]<Math.min(leftMax[j],rightMax[j]))
                sum+=Math.min(leftMax[j],rightMax[j])-height[j];
        }
        System.out.println(sum);
    }

}
